package com.coderman.common.starter.idempotent.service;

import com.coderman.common.starter.idempotent.service.config.RedisProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * Description:
 * date: 2020/9/25 5:11 下午
 *
 * @author fanchunshuai
 * @version 1.0.0
 * @since JDK 1.8
 */
@Service
public class LockService {
    @Resource(name = "redissionLockImpl")
    private DistributedLocker redissionLock;

    @Resource(name = "redisLuaScriptLockImpl")
    private DistributedLocker redisLuaScriptLock;

    @Autowired
    private RedisProperties redisProperties;

    /**
     * 根据配置选择分布式锁的实现
     * @return
     */
    public DistributedLocker getDistributedLocker(){
        if(redisProperties.getLockService().equals("redissionLockImpl")){
            return redissionLock;
        }
        return redisLuaScriptLock;
    }

}
